package com.atguigu.classroom.vod.api;

import com.atguigu.classroom.model.vod.Course;
import com.atguigu.classroom.result.Result;
import com.atguigu.classroom.vo.vod.CourseVo;
import com.atguigu.classroom.vod.service.CourseService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Api(tags = "微信公众号查询课程接口")
@RestController
@RequestMapping(value = "/api/vod/course/")
public class CourseApiController {
    @Autowired
    private CourseService courseService;
    @ApiOperation("根据关键字查询课程")
    @GetMapping("inner/findByKeyword/{keyword}")
    public List<Course> findByKeyword(@PathVariable String keyword){
        return courseService.getCourseListByKeyword(keyword);
    }
    @ApiOperation("根据课程分类分页查询课程列表")
    @GetMapping("{subjectParentId}/{page}/{limit}")
    public Result findPageCourse(@PathVariable Long subjectParentId,
                                 @PathVariable int page,
                                 @PathVariable int limit) {
        Page<CourseVo> coursePage=courseService.findPageCourseWithSPIdAPI(subjectParentId,page,limit);
        return Result.ok(coursePage);
    }
    @ApiOperation("根据ID查询课程详细信息")
    @GetMapping("getInfo/{courseId}")
    public Result getInfo(@PathVariable Long courseId){
        Map<String,Object> courseInfo=courseService.getCourseInfoAPI(courseId);
        return Result.ok(courseInfo);
    }
    @ApiOperation("根据ID查询课程基本信息")
    @GetMapping("inner/getById/{courseId}")
    public Course getById(@PathVariable Long courseId){
        return courseService.getById(courseId);
    }
}
